C
C     ..................................................................
C
C        SUBROUTINE TTEST
C
C        PURPOSE
C           TO FIND CERTAIN T-STATISTICS ON THE MEANS OF POPULATIONS.
C
C        USAGE
C           CALL TTEST (A,NA,B,NB,NOP,NDF,ANS)
C
C        DESCRIPTION OF PARAMETERS
C           A   - INPUT VECTOR OF LENGTH NA CONTAINING DATA.
C           NA  - NUMBER OF OBSERVATIONS IN A.
C           B   - INPUT VECTOR OF LENGTH NB CONTAINING DATA.
C           NB  - NUMBER OF OBSERVATIONS IN B.
C           NOP - OPTIONS FOR VARIOUS HYPOTHESES..
C                 NOP=1--- THAT POPULATION MEAN OF B = GIVEN VALUE A.
C                          (SET NA=1)
C                 NOP=2--- THAT POPULATION MEAN OF B = POPULATION MEAN
C                          OF A, GIVEN THAT THE VARIANCE OF B = THE
C                          VARIANCE OF A.
C                 NOP=3--- THAT POPULATION MEAN OF B = POPULATION MEAN
C                          OF A, GIVEN THAT THE VARIANCE OF B IS NOT
C                          EQUAL TO THE VARIANCE OF A.
C                 NOP=4--- THAT POPULATION MEAN OF B = POPULATION MEAN
C                          OF A, GIVEN NO INFORMATION ABOUT VARIANCES OF
C                          A AND B.  (SET NA=NB)
C           NDF - OUTPUT VARIABLE CONTAINING DEGREES OF FREEDOM ASSOCI-
C                 ATED WITH T-STATISTIC CALCULATED.
C           ANS - T-STATISTIC FOR GIVEN HYPOTHESIS.
C
C        REMARKS
C           NA AND NB MUST BE GREATER THAN 1, EXCEPT THAT NA=1 IN
C           OPTION 1. NA AND NB MUST BE THE SAME IN OPTION 4.
C           IF NOP IS OTHER THAN 1, 2, 3 OR 4, DEGREES OF FREEDOM AND
C           T-STATISTIC WILL NOT BE CALCULATED.  NDF AND ANS WILL BE
C           SET TO ZERO.
C
C        SUBROUTINES AND FUNCTION SUBPROGRAMS REQUIRED
C           NONE
C
C        METHOD
C           REFER TO OSTLE, BERNARD, 'STATISTICS IN RESEARCH', IOWA
C           STATE COLLEGE PRESS, 1954, CHAPTER 5.
C
C     ..................................................................
C
      SUBROUTINE TTEST (A,NA,B,NB,NOP,NDF,ANS)
      DIMENSION A(1),B(1)
C
C     INITIALIZATION
C
      NDF=0
      ANS=0.0
C
C     CALCULATE THE MEAN OF A
C
      AMEAN=0.0
      DO 110 I=1,NA
  110 AMEAN=AMEAN+A(I)
      FNA=NA
      AMEAN=AMEAN/FNA
C
C     CALCULATE THE MEAN OF B
C
  115 BMEAN=0.0
      DO 120 I=1,NB
  120 BMEAN=BMEAN+B(I)
      FNB=NB
      BMEAN=BMEAN/FNB
C
      IF(NOP-4) 122, 180, 200
  122 IF(NOP-1) 200, 135, 125
C
C     CALCULATE THE VARIANCE OF A
C
  125 SA2=0.0
      DO 130 I=1,NA
  130 SA2=SA2+(A(I)-AMEAN)**2
      SA2=SA2/(FNA-1.0)
C
C     CALCULATE THE VARIANCE OF B
C
  135 SB2=0.0
      DO 140 I=1,NB
  140 SB2=SB2+(B(I)-BMEAN)**2
      SB2=SB2/(FNB-1.0)
C
      GO TO (150,160,170), NOP
C
C        OPTION 1
C
  150 ANS=((BMEAN-AMEAN)/SQRT(SB2))*SQRT(FNB)
      NDF=NB-1
      GO TO 200
C
C        OPTION 2
C
  160 NDF=NA+NB-2
      FNDF=NDF
      S=SQRT(((FNA-1.0)*SA2+(FNB-1.0)*SB2)/FNDF)
      ANS=((BMEAN-AMEAN)/S)*(1.0/SQRT(1.0/FNA+1.0/FNB))
      GO TO 200
C
C        OPTION 3
C
  170 ANS=(BMEAN-AMEAN)/SQRT(SA2/FNA+SB2/FNB)
      A1=(SA2/FNA+SB2/FNB)**2
      A2=(SA2/FNA)**2/(FNA+1.0)+(SB2/FNB)**2/(FNB+1.0)
      NDF=A1/A2-2.0+0.5
      GO TO 200
C
C        OPTION 4
C
  180 SD=0.0
      D=BMEAN-AMEAN
      DO 190 I=1,NB
  190 SD=SD+(B(I)-A(I)-D)**2
      SD=SQRT(SD/(FNB-1.0))
      ANS=(D/SD)*SQRT(FNB)
      NDF=NB-1
C
  200 RETURN
      END
